package com.mall.controller;

import com.mall.pojo.SmsFlashPromotionSession;
import com.mall.service.FlashSessionService;
import com.mall.utils.Result;
import com.mall.vo.FlashSessionSelectListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class FlashSessionController {

    @Autowired
    private FlashSessionService sessionService;

    /**
     * 获取所有秒杀时间段
     *
     * @return
     */
    @GetMapping("/list")
    public Result<List<SmsFlashPromotionSession>> list() {
        List<SmsFlashPromotionSession> result = sessionService.list();
        return Result.success(result, "操作成功");
    }

    /**
     * 添加秒杀场次
     *
     * @param promotionSession
     * @return
     */
    @PostMapping("/create")
    public Result<Integer> create(@RequestBody SmsFlashPromotionSession promotionSession) {
        Integer count = sessionService.create(promotionSession);
        return Result.success(count, "操作成功");
    }

    /**
     * 删除秒杀场次
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result<Integer> delete(@PathVariable Integer id) {
        Integer count = sessionService.delete(id);
        return Result.success(count, "操作成功");
    }

    /**
     * 修改秒杀场次
     *
     * @param id
     * @param promotionSession
     * @return
     */
    @PostMapping("/update/{id}")
    public Result<Integer> update(@PathVariable Integer id, @RequestBody SmsFlashPromotionSession promotionSession) {
        Integer count = sessionService.update(id, promotionSession);
        return Result.success(count, "操作成功");
    }

    /**
     * 修改秒杀场次启用状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public Result<Integer> updateStatus(@PathVariable Integer id, @RequestParam Integer status) {
        Integer count = sessionService.updateStatus(id, status);
        return Result.success(count, "操作成功");
    }

    /**
     * 获取全部可选场次及其数量,场次处于启用状态
     * @param flashPromotionId
     * @return
     */
    @GetMapping("/selectList")
    public Result<List<FlashSessionSelectListVo>> selectList(@RequestParam Integer flashPromotionId) {
        List<FlashSessionSelectListVo> result = sessionService.selectList(flashPromotionId);
        return Result.success(result, "操作成功");
    }


    //todo:获取场次详情 /flashSession/{id}

}
